<?php
/**
 * Author: DefinitlyEvil
 * Created at: 2020/4/14 19:37
 */

namespace App\Tools;


class Pattern
{
    const ALPHANUMERIC = '/^[A-Za-z0-9_]+$/';
    const USERNAME = '/^[A-Za-z0-9_]{3,20}$/';

    const TITLE = "/^[A-Za-z0-9\\s\x{4e00}-\x{9fa5}]+$/u";

    const IMAGE_CODE_ID = '/^[a-z0-9]{40}$/';
    const IMAGE_CODE_VALUE = '/^[A-Za-z0-9]{4}$/';

    /**
     * @param $pattern
     * @param $target
     * @return boolean
     */
    public static function matches($pattern, $target) {
        $x = preg_match_all($pattern, $target);
        if($x === false) return false;
        if($x <= 0) return false;
        if($x > 0) return true;
        return false;
    }
}